<%@ page language="java" pageEncoding="utf-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
${aier_doctype}
<html <s:property value="aier_html_xmlns" escape="false"/>>
<head>
<meta http-equiv="Content-Type" content="${aier_content_type}" />
<meta name="keywords" content="${aier_keyworks}" />
<meta name="description" content="${aier_description}" />
<title>${aier_title}</title>
<link rel="stylesheet" href="${aier_css_url}${aier_jqui_css}ui.css" />
<link rel="Stylesheet" href="${aier_css_url}jq/jq.css" />
<link rel="stylesheet" href="${aier_css_url}social/module/jq-msg.css" />

<link rel="Stylesheet" href="${aier_css_url}social/module/emotion.css" />
<link rel="stylesheet" href="${aier_css_url}social/module/reset.css" />
<link rel="stylesheet" href="${aier_css_url}social/module/btn.css" />
<link rel="stylesheet" href="${aier_css_url}social/user/homeForums/common.css" />
<link rel="stylesheet" href="${aier_css_url}social/user/homeForums/homeforums.css" />
<link rel="stylesheet" href="${aier_css_url}social/module/uploadphoto.css" />
<link rel="stylesheet" href="${aier_css_url}social/module/xxs.css" />

<script type="text/javascript" src="${aier_js_url}j.js"></script>
<script type="text/javascript" src="${aier_js_url}b.js"></script>
<script type="text/javascript" src="${aier_js_url}${aier_jqui_js}ui.js"></script>
<script type="text/javascript" src="${aier_js_url}jp/msg.js"></script>
<script type="text/javascript" src="${aier_js_url}97/WdatePicker.js"></script>
<script type="text/javascript" src="${aier_js_url}jq/cn.js"></script>
<script type="text/javascript" src="${aier_js_url}jq/jq.js"></script>
<script type="text/javascript" src="${aier_js_url}lib/block.js"></script>
<script type="text/javascript" src="${aier_js_url}lib/afu.js"></script>
<script type="text/javascript" src="${aier_js_url}${aier_jqui_js}ui.js"></script>
<script type="text/javascript" src="${aier_js_url}trantime/jquery-aier.js"></script>
<script type="text/javascript" src="${aier_js_url}aier-ui.js"></script>

<script type="text/javascript">
// var timea = new Date().getTime();
$(document).ready(function() {
    cloneLib = getCloneLib();
});

</script>
</head>
<body>

	<!-- 顶栏 -->
	<s:action name="userhomecomm_homeHead" namespace="/user" executeResult="true"></s:action>
	<!-- 顶栏结束 -->

    <!-- ^^模版层开始 -->
    <div class="layer-clone" style="display:none;">
        <!--  xxs-without-avatar  -->
        <div class="node-clone" data-title="xxs">
            <div class="xxs-item xxs-with-avatar" data-xxsid="" data-xxsuid=""><div class="xxs-avatar"><a href=""><img src="" alt=""></a></div><div class="xxs-detail"><div class="xxs-name"><a></a></div><div class="xxs-text"></div><ul class="xxs-media-pre xxs-single-img" style=""><li><div><img class="zoom-in" src="" alt="" data-imgname></div></li></ul><div class="xxs-box xxs-box-no-o xxs-extend" style="display:none"><div class="top-function clearfix"><a class="btn-collapse"><i class="icon-1 icon-1-collapse"></i><span>收起</span></a></div><div class="media"><img class="zoom-out" src="" alt=""></div></div><div class="xxs-box xxs-box-has-o" style=""><div class="xxs-name-o"><a href=""></a></div><div class="text"></div><ul class="xxs-media-pre xxs-single-img" style=""><li><div><img class="zoom-in" src="" alt="" data-imgname></div></li></ul><div class="xxs-extend" style="display:none"><div class="top-function clearfix"><a class="btn-collapse"><i class="icon-1 icon-1-collapse"></i><span>收起</span></a></div><div class="media"><img class="zoom-out" src="" alt=""></div></div><div class="xxs-function-o clearfix"><div class="xxs-handle"><a class="btn xxs-like-btn"><em class="icon-1 icon-1-like"></em><strong></strong></a><span>|</span><a class="btn xxs-zhuanfa">转发<strong></strong></a><span>|</span><a class="btn xxs-shoucang">收藏<strong></strong></a><span>|</span><a class="btn xxs-zhuanfa">评论<strong></strong></a></div><div class="xxs-from"><a data-stamp></a></div></div></div><div class="xxs-function clearfix"><div class="xxs-handle"><a class="btn xxs-like-btn"><em class="icon-1 icon-1-like"></em><strong></strong></a><span>|</span><a class="btn-forward">转发<strong></strong></a><span>|</span><a class="btn-favourite">收藏<strong></strong></a><span>|</span><a class="btn-xxs-comment">评论<strong></strong></a></div><div class="xxs-from"><a data-stamp></a></div></div><div class="xxs-comment" style="display:none"><div class="input-box"><div class="textarea-bar"><textarea class="comment-textarea" data-id=""></textarea></div><div class="submit-bar clearfix"><div class="btn-emotion-comment"><a href="javascript:void(0);" class="icon-1 icon-1-emotion btn-emotion"></a></div><div class="left-reblog"><div class="select select-reblog"><label><input type="checkbox">同时转发到我的新鲜事</label></div><div class="select select-orig"><label><input type="checkbox">同时评论给原作者</label></div></div><div class="right-submit"><a class="btn-orange-2"><span>评论</span></a></div></div></div><div class="xxs-comment-list" id=""></div></div></div><div class="xxs-screen"><a href="javascript:void(0);" class="btn-screen-delete" onclick="">x</a></div></div>
        </div><!-- xxs over -->

        <div class="node-clone" data-title="xxscomment">
            <div class="comment-item" data-xxfcid="" data-xxfcuid=""><div class="comment-avatar"><a><img src="" alt=""></a></div><div class="comment-content"><a class="commenter-name"><span class="name"></span><span>:</span></a><span class="comment-text"></span><span>（</span><span class="comment-time" data-time data-stamp></span><span>）</span><div class="comment-function clearfix"><div class="right"><a href="javascript:void(0);" class="open-cc">回复</a></div><div class="comment-comment" style="display: none;"><div class="cc-textarea"><textarea></textarea></div><div class="cc-submit-bar clearfix"><a class="btn-emotion-reply"><i class="icon-1 icon-1-emotion"></i></a><label><input type="checkbox">同时转发到我的新鲜事</label><a class="btn-cc-submit btn-orange-2"><span>评论</span></a></div></div></div></div></div>
        </div>
    </div>

    <!-- $$$ 模版层结束 -->

	<div class="window-content">

		<!-- wrap  -->

		<div class="wrap wrap-homepage wrap-tri-col hasgap clearfix">

			<s:action name="userhomecomm_homeLeft" namespace="/user"
				executeResult="true"></s:action>

			<!-- 主区域 (右  -->
			<div class="main-area clearfix">

				<!-- 中间栏 -->
				<div class="message-stream">

					<div class="post-fresh-news">
						<div class="hello-sentense">有什么亲子趣事想告诉大家？</div>

						<div class="textarea-box">
							<textarea id="xxsTextarea"></textarea>
						</div>

						<div class="bottom-bar clearfix">

							<div class="functions">
								<a class="btn btn-emotion-fresh">
									<em class="icon-1 icon-1-emotion"></em><span>表情</span> 
								</a> 
								<a class="btn btn-photo" id="uploadPhoto">
									<em class="icon-1 icon-1-picture"></em><span>图片</span>
								</a>
							</div>

							<div class="xxs-submit">
								<a href="javascript:void(0);" class="btn btn-fabu"> <em id = "publish"
									class="icon-1 icon-1-fabu"></em> </a>
							</div>
						</div>
					</div>



					<div class="message-stream-list child-message-list clearfix" id="freshList">


					</div>
					
					<div id = "page"></div>
					
				</div>
				
				<!-- 右栏 -->
				<s:action name="userhomecomm_homeRight" namespace="/user" executeResult="true"></s:action>
		
		

				
			</div>
			<!-- 回到顶部 -->
			<s:action name="userhomecomm_backToTop" namespace="/user" executeResult="true"></s:action>
			
		</div>

	<!-- footer copyright -->
	<s:action name="userhomecomm_homeFooter" namespace="/user" executeResult="true"></s:action>
	<!-- /footer copyright -->
	</div>
	
	
	<div id="uploadPhotoBox" style="display:none;">
		<div class="title">上传图片</div>

		<div class="select">
			
			<a class="btn-select">
				<label for="selectPhoto">
					<span>选择图片</span>
				</label>
			</a>
			<input type="file" id="selectPhoto" style="" name = "selectPhoto"/>
		</div>

		<div class="uploading" style="display:none">正在上传</div>

		<div id="confirmPhoto" style="display:none">
			<div id="photoName"></div>
			<div id="delete"><a class="btn btn-orange-2"><span>重新上传</span></a></div>
		</div>
	
	</div>
	
	<div id="deleteConfirm" style="display: none;" title="删除">
        <p>你确定要删除这条新鲜事吗?</p>
    </div>
    

<!-- 转发这条新鲜事 -->
<div class="dialog-xxs-forward" id="dialogForward" title="转发" style="display:none;">
    <div class="box-textarea">
        <textarea id="forward"></textarea>
    </div>

    <div class="submit-bar">
        <div class="left">
            <div class="btn-emotion-forward"></div>
            <div class="select-comment">
                <div>
                    <label>
                        <input type="checkbox" id = "commentFlag">
                        同时评论给该作者
                    </label>
                </div>
            </div>
        </div>
    </div>

</div>


<div id="list"></div>
<div id="hidden"></div>


<script type="text/javascript">

// global 1

var fgid = "${fgid}";

var page = 1;       // 当前页
var page_size = 15; // 每页的记录数
// 关注的昵称列表（@时用）
var followList = null;

// 上传图片
$("body").click(function(){
 	$("#uploadPhotoBox").hide();
});

$('#uploadPhoto,#uploadPhotoBox').click(function(event) {
    event.stopPropagation();
});

$("#uploadPhoto").click(function() {
//    if ( !$("#uploadPhotoBox").hasClass("open") ) {
//    	 $("#uploadPhotoBox").addClass("open");
//    }

//    if (!$('#uploadPhotoBox')[0]) {
//        $('body').append('<div id="uploadPhotoBox"></div>');
//    } else {
//    	$('#uploadPhotoBox').toggle();
 //   }
    $('#uploadPhotoBox').toggle();
    $('#uploadPhotoBox').css({
        top: $(this).offset().top + $(this).height() + 8,
        left: $(this).offset().left
    });
});


$("#selectPhoto").live('change', function(){
	upfile();
	$(".select").hide();
	$(".uploading").show();
});

var imgName;

function upfile() {
    var temp = $('#selectPhoto').val().substring($('#selectPhoto').val().lastIndexOf('.')).toLowerCase();
	try {$.ajaxFileUpload({
		url : "${aier_url}commonjs/image_uploadImage${aier_suffix}?photoName="+temp+"&&imageUrl=${fresh_upload_url}&&type=1",
		secureuri : false,
		fileElementId : 'selectPhoto',
		dataType : 'json',
		success : function(data, status) {
		    if (data.s == 1) {
			    imgName = data.imageName;
                $(".uploading").hide();
                $('#confirmPhoto').show();
                $('#photoName').html(imgName);
		    } else {
		        $().message("图片上传出错，请重新上传！");
		        $(".uploading").hide();
                $('.select').show();
		    }
			
		},
		error : function(data, status, e) {
			$().message("服务器连接超时");
			$(".uploading").hide();
            $('.select').show();
		}
	});
	} catch (e) {
		$(".uploading").hide();
		$('.select').show();
		$().message("服务器连接超时");
	}
};
	
// 删除图片
$("#delete").click(function(){
   
     var fun=function(data){
        if(data.s==1){
            imgName = "";
            $('#confirmPhoto').hide();
            $('#selectPhoto').val("");
            $('.select').show();
        } else {
            $().message("删除失败，请稍后再试！"); 
        }
    };
    exeAjax(
         ajaxUrl("${aier_url}${aier_urijs}userhomeforums_deleteImage${aier_suffix}"),
         fun,{
             "imageName":imgName
    });
    
});


// 解析表情
$(document).ready(function() {
    $('.text,.xxs-text,.comment-text').each(function() {
        $(this).tranText({
        	emotionUrl:'${aier_js_url}trantime/emotions.js'
        });
    });
});

    
// 发布框里的按钮
$(document).ready(function(){
	// 插入表情 - 发表新鲜事的框
	$('.btn-emotion-fresh').click(function(){
		$(this).sinaEmotion({
			emotionUrl: '${aier_js_url}trantime/emotions.js',
			target : $('#xxsTextarea')
		});
	});
});

// 评论框里的按钮
function commentEmotion() {
	$('.btn-emotion-comment').click(function(){
		$(this).sinaEmotion({
			emotionUrl: '${aier_js_url}trantime/emotions.js',
			target : $(this).closest('.input-box').find('textarea')
		});
	});
}

//回复框里的按钮
function replyEmotion() {
	$('.btn-emotion-reply').click(function(){
		$(this).sinaEmotion({
			emotionUrl: '${aier_js_url}trantime/emotions.js',
			target : $(this).closest('.comment-comment').find('textarea')
		});
	});
}
	
	
	
	
$(document).ready(function() {
    
    if (fgid != null && fgid != "") {
        followFresh(fgid);
    } else {
        searchAllFresh(page);
    }
    searchFollowForSpecial();
});	
    	
// 发布新鲜事
$("#xxsTextarea").live('input',function(){
	if($(this).val().length > 300) {
		$().message('超出字数限制, 最多输入300字');
		$(this).css('background-color','#ffaaaa');
	} else {
		$(this).css('background-color','#fff');
	}
});
    
    
    
$("#publish").click(
    function() {
        var content = $("#xxsTextarea").val();
        if ((null == content.trim() || content.trim() == "") && (imgName == null || imgName == "")) {
            $().message("请输入内容");
            return
        }
        var fun=function(data){
           if(data.s==1){
               searchAllFresh(page);
               $("#xxsTextarea").val("");
               imgName = "";
               $('#confirmPhoto').hide();
               $('#selectPhoto').val("");
               $('.select').show();
           } else {
               $().message("发布失败，请稍后再试！"); 
           }
       };
       exeAjax(
            ajaxUrl("${aier_url}${aier_urijs}userhomeforums_publishFresh${aier_suffix}"),
            fun,{
                "content":content,
                "imageName":imgName,
                "power":0
       });
    }
);


// 获取所有关注昵称列表（@时用）
function searchFollowForSpecial() {
	var fun=function(data){
        if(data.s==1){
        	followList = data.followList;
        }
    };
    exeAjax(
         ajaxUrl("${aier_url}${aier_urijs}usermyfollow_searchFollowForSpecial${aier_suffix}"),
         fun,{
             
    });
	
}
    
// 获取新鲜事列表
function searchAllFresh(nowpage) {
    page = nowpage;
    var fun=function(data){
           if(data.s==1){
        	   $("#freshList").html("");
               if (data.freshList != null) {
                   appendFresh(data.freshList,data.uid);
               } 
               // 更新分页显示
               page = data.page;
               toLoadPage(page, page_size, data.page_count, data.count, "page", "searchAllFresh", null, null);
               if (data.count == 0) {
                   $("#page").css("display","none");
               } else {
                   $("#page").css("display","block");
               }
               
           }
       };
       exeAjax(
            ajaxUrl("${aier_url}${aier_urijs}userhomeforums_searchAllFresh${aier_suffix}"),
            fun,{
                "page":page,
                "page_size":page_size
       });
}
    
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


function appendFresh(freshList,uid) {
    $('#freshList').empty();

    for (var i=0; i<freshList.length; i++) {

        var xxshtml = searchCloneLib('xxs');
        var fresh = freshList[i];
        var avatarlink = '${aier_url}user/uccomm_userCenter.shtml?in_uid=';
        var smallavatar = '${get_picturl_url}small/';
        var smallfresh ='${fresh_get_url}small/';
        var bigfresh = '${fresh_get_url}big/';
        var time = fresh.cdate.split("T")[0]+" "+fresh.cdate.split("T")[1];
        time = time.replace(/-/g,'\/');

        xxshtml.attr({'data-xxsid':fresh.fid,'data-xxsuid':fresh.uid});
        xxshtml.children('.xxs-avatar').children('a').attr('href',avatarlink+fresh.uid)
            .children('img').attr('src',smallavatar+fresh.headimg);
        xxshtml.children('.xxs-detail').find('.xxs-name a').text(fresh.nickname);
        xxshtml.children('.xxs-detail').children('.xxs-text').text(fresh.content);
        xxshtml.children('.xxs-detail').children('.xxs-text').tranText();

        xxshtml.children('.xxs-detail').children('.xxs-function').children('.xxs-from').children('a').attr({'data-time':time,'title':time}).parseStampPre().parseStamp();
        xxshtml.children('.xxs-detail').find('.xxs-comment>.xxs-comment-list').attr('id','comment'+fresh.fid);

        // 判断类型
        if (fresh.type == 1) {
            var fr = fresh.fresh;
            var rtime = fr.cdate.split("T")[0]+" "+fr.cdate.split("T")[1];
            rtime = rtime.replace(/-/g,'\/');
            // console.log(fr.stamp);
            xxshtml.children('.xxs-detail').children('.xxs-media-pre').remove();
            xxshtml.children('.xxs-detail').children('.xxs-box-no-o').remove();
            var hasohtml=xxshtml.children('.xxs-detail').children('.xxs-box-has-o');
            hasohtml.find('.xxs-name-o a').attr('href',avatarlink+fr.uid).text(fr.nickname);
            hasohtml.children('.text').text(fr.content);
            hasohtml.children('.text').tranText();
            hasohtml.find('.xxs-from a').attr({'data-time':rtime,'title':rtime}).parseStampPre().parseStamp();

            if (!isnull(fr.img)) {
                hasohtml.children('.xxs-media-pre').find('.zoom-in').attr({'src':smallfresh+fr.img,'data-imgname':fr.img});
                // hasohtml.children('.xxs-extend').find('.zoom-out').attr('src',bigfresh+fr.img);
            } else {
                hasohtml.children('.xxs-media-pre').remove();
                hasohtml.children('.xxs-extend').remove();
            };
            if (fr.pcount != 0) {
                hasohtml.find('.xxs-like-btn strong').text('\('+fr.pcount+'\)');
            };
            if (fr.tcount != 0) {
                hasohtml.find('.xxs-zhuanfa strong').text('\('+fr.tcount+'\)');
            };
            if (fr.ccount != 0) {
                hasohtml.find('.xxs-pinglun strong').text('\('+fr.ccount+'\)');
            };
        } else {
            xxshtml.children('.xxs-detail').children('.xxs-box-has-o').remove();
            var noomediahtml = xxshtml.children('.xxs-detail').children('.xxs-media-pre');
            var noohtml = xxshtml.children('.xxs-detail').children('.xxs-box-no-o');
            xxshtml.find('.left-reblog>.select-orig').remove();

            if (!isnull(fresh.img)) {
                noomediahtml.find('.zoom-in').attr({'src':smallfresh+fresh.img, 'data-imgname':fresh.img});
                // noohtml.find('.zoom-out').attr('src',bigfresh+fresh.img);
            } else {
                noomediahtml.remove();
                noohtml.remove();
            };
        };
        // 底部功能
        if (fresh.pflag == 1) {
            xxshtml.children('.xxs-detail').children('.xxs-function').find('.xxs-like-btn>em').addClass('has-liked');
        };
        if (fresh.pcount != 0){
            xxshtml.children('.xxs-detail').children('.xxs-function').find('.xxs-like-btn strong').text('\('+fresh.pcount+'\)');
        };
        if (fresh.tcount != 0) {
            xxshtml.children('.xxs-detail').children('.xxs-function').find('.xxs-like-btn strong').text('\('+fresh.tcount+'\)');
        };
        if (fresh.fflag == 1) {
            xxshtml.children('.xxs-detail').children('.xxs-function').find('.btn-favourite').addClass('has-fav');
        };
        if (fresh.ccount != 0) {
            xxshtml.children('.xxs-detail').children('.xxs-function').find('.btn-xxs-comment strong').text('\('+fresh.ccount+'\)');
        };

        if (uid == fresh.uid) {
            xxshtml.find('.xxs-screen a').attr('onclick','deleteFresh\('+fresh.fid+'\)\;');
            xxshtml.find('.left-reblog>.select-reblog').remove();
        } else {
            xxshtml.children('.xxs-screen').remove();
        }
        $('#freshList').append(xxshtml);


        // if ( i = freshList.length-1) {


        //     timeb = new Date().getTime();
        //     tgap = timeb-timea;
        //     console.log('花费了'+ tgap +'豪秒');
        // };


    } // end for循环


    commentEmotion();


    // 预览图和完整图切换

    //缩小
    $('.zoom-out,.btn-collapse').click(function() {
        $(this).parents('.xxs-extend').css('display', 'none').prev('.xxs-media-pre').css('display', 'block');
    });

    //放大
    $('.zoom-in').click(function() {
        var $this = $(this);
        var $zoomout = $this.parents('.xxs-media-pre').next('.xxs-extend').find('.zoom-out');

        if ( isnull( $zoomout.attr('src') ) ) {
            var bigfresh = '${fresh_get_url}big/';
            var imgname = $this.attr('data-imgname');
            $zoomout.attr('src',bigfresh+imgname);
        };
        
        $(this).parents('.xxs-media-pre').css('display', 'none').next('.xxs-extend').css('display', 'block');
    });

     
     // 称赞或取消赞（ptype为0赞1取消赞）
    $('.xxs-function .xxs-like-btn').click(function(){

       


        var thisobj = $(this);
        var ptype;
        if( thisobj.children('em').hasClass('has-liked') ){
            ptype = 1;
        } else {
            ptype = 0;
        }
        var fid = thisobj.closest('.xxs-item').attr('data-xxsid');
        var fun=function(data){
            if(data.s==1){
             
                if (ptype == 0) {
                    // 赞
                    if (data.pcount != null && data.pcount!=0) {
                        thisobj.html('<em class="icon-1 icon-1-like has-liked"></em>('+data.pcount+')');
                    } else {
                        thisobj.html('<em class="icon-1 icon-1-like has-liked"></em>');
                    }
                } else {
                    // 取消赞
                    if (data.pcount != null && data.pcount!=0) {
                        thisobj.html('<em class="icon-1 icon-1-like"></em>('+data.pcount+')');
                    } else {
                        thisobj.html('<em class="icon-1 icon-1-like"></em>');
                    }
                }
            }
        };
        exeAjax(
             ajaxUrl("${aier_url}${aier_urijs}userhomeforums_praiseFresh${aier_suffix}"),
             fun,{
                 "fid":fid,
                 "ptype":ptype
        });
    });


    
    // 转发
    $('.btn-forward').click(function(){
	    var fid = $(this).closest('.xxs-item').attr('data-xxsid');
	    $('#dialogForward').dialog({
		    //背景变暗
		    modal: true,
		    autoOpen : false,
		    show : "fade",
		       hide : "fade",
		    width : "400",
		    height : "240",
		    buttons: {
		        "确定": function() {
		            // 转发新鲜事
		            var content = $("#forward").val();
		            if (isnull(content)) {
		                content = "转发";
		            } 
		            var cflag = 0;
		            if ($('#commentFlag').attr("checked") == "checked") {
		                cflag = 1;
		            }
		            var fun=function(data){
		                   
		                   if(data.s==1){
		                       // 刷新列表
		                       searchAllFresh(page);
		                       $('#dialogForward').dialog('close');
		                       $("#forward").val("");
                               $("#commentFlag").attr("checked",false);
		                   } else {
		                       $().message("转发失败，请稍后再试！");
		                   }
		               };
		               exeAjax(
		                    ajaxUrl("${aier_url}${aier_urijs}userhomeforums_transmitFresh${aier_suffix}"),
		                    fun,{
		                        "fid":fid,
		                        "content":content,
		                        "cflag":cflag
		               });
		        
		        },"取消": function() {
		            $( this ).dialog( "close" );
		            $("#forward").val("");
                    $("#commentFlag").attr("checked",false);
		        }
		    }
		});
		$('#dialogForward').dialog('open');
	});
	
	// 收藏或取消收藏
	$('.btn-favourite').click(function(){
	    var thisobj = $(this);
	    var fid = thisobj.closest('.xxs-item').attr('data-xxsid');
	    
	    if (thisobj.hasClass('has-fav')) {
		    // 取消收藏
		    thisobj.removeClass('has-fav');
		    unfavorite(thisobj,fid);
		
		} else {
			// 收藏
			thisobj.addClass('has-fav');
			favorite(thisobj,fid);
	    }
	
	});
	// 收藏新鲜事
	function favorite(thisobj,fid) {
        var fun=function(data){
           if(data.s==1){
               $().message("收藏成功");
               // 将收藏变为取消收藏
               thisobj.html("取消收藏");
               //thisobj.removeClass("btn-favourite").addClass("btn-un-fav");
           } else {
           
               $().message("收藏失败，请稍后再试！");
           }
       };
       exeAjax(
            ajaxUrl("${aier_url}${aier_urijs}userhomeforums_favoriteFresh${aier_suffix}"),
            fun,{
                "fid":fid
       });
    }
	// 取消收藏
	function unfavorite(thisobj,fid) {
        var fun=function(data){
           if(data.s==1){
               $().message("取消收藏成功");
               // 将取消收藏变为收藏
               thisobj.html("收藏");
               //thisobj.removeClass("btn-un-fav").addClass("btn-favourite");
               
           } else {
               $().message("取消收藏失败，请稍后再试！");
           }
       };
       exeAjax(
            ajaxUrl("${aier_url}${aier_urijs}userhomeforums_deleteFFByUid${aier_suffix}"),
            fun,{
                "fid":fid
       });
    }
	
	// 评论
	$('.btn-xxs-comment').click(function(){
	    var thisobj = $(this);
        var fid = thisobj.closest('.xxs-item').attr('data-xxsid');
	    // 获取新鲜事的评论
        searchComment(fid,thisobj);

        thisobj.closest('.xxs-detail').find('.xxs-comment').toggle();
	    
	    thisobj.closest('.xxs-detail').find('.comment-textarea').focus();
	    
	    // commentEmotion();
	    
	});
	
	// 评论
	$('.right-submit').click(function(){
		//commentEmotion();
		
	    var thisobj = $(this);
        var fid = thisobj.closest('.xxs-item').attr('data-xxsid');
        var content = thisobj.closest('.xxs-item').find('textarea').val();
        var rcontent = thisobj.closest('.xxs-item').find('xxs-text').val();
        var rfcuid = thisobj.closest('.xxs-item').attr('data-xxsuid');


        if (content.length ==0 ) {
            $().message("评论内容不能为空！");
            return;
        }
        if (content.length > 200) {
            $().message("评论内容太长！");
            return;
        }
        var input = thisobj.closest('.xxs-item').find('input');
        var tflag = 0;
        var cflag = 0;
        if (input.length == 1) {
            if (input.eq(0).attr("checked") == "checked") {
                tflag = 1;
            }
        } else {
            if (input.eq(0).attr("checked") == "checked") {
                tflag = 1;
            }
            if (input.eq(1).attr("checked") == "checked") {
                cflag = 1;
            }
        }
        // 评论
        var fun=function(data){
           if(data.s==1){
               thisobj.closest('.xxs-item').find('textarea').val("");
               if (input.length == 1) {
                    input.eq(0).attr("checked",false);
               } else {
                    input.eq(0).attr("checked",false);
                    input.eq(1).attr("checked",false);
               }
               // 刷新评论列表
               searchComment(fid,thisobj);
               // 修改评论的次数
               thisobj.closest('.xxs-item').find('.btn-xxs-comment ').html("评论("+data.ccount+")");
               
           } 
       };
       exeAjax(
            ajaxUrl("${aier_url}${aier_urijs}userhomeforums_commentFresh${aier_suffix}"),
            fun,{
                "fid":fid,
                "rfcuid":rfcuid,
                "content":content,
                "rcontent":rcontent,
                "ctype":1,
                "flag":tflag,
                "cflag":cflag
       });
        
	});
	
}
    
// $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$


// 获取评论列表
function searchComment(fid,thisobj) {
    // 获取新鲜事的评论
    var fun=function(data){
        if(data.s==1){
            if (data.fcList != null && data.fcList.length > 0 ) {
                var commentList = thisobj.parents('.xxs-detail').find('.xxs-comment-list');
                commentList.empty();
                for (var i=0;i<data.fcList.length;i++) {
                    var $xxscomment = searchCloneLib('xxscomment');
                    var fc = data.fcList[i];
                    var time = fc.cdate.split("T")[0]+" "+fc.cdate.split("T")[1];
                    time = time.replace(/-/,'\/');
                    var smallimg = "${get_picturl_url}small/";
                    
                    $xxscomment.attr({'data-xxfcid':fc.fid,'data-xxfcuid':fc.fcuid})
                        .find('.comment-avatar img').attr('src',smallimg+fc.headimg);
                    $xxscomment.find('.name').text(fc.nickname);
                    $xxscomment.find('.comment-text').html(fc.content).tranText();
                    $xxscomment.find('.comment-time').attr({'data-time':time,'title':time}).parseStampPre().parseStamp();
                    commentList.append($xxscomment);
                } // end for 
            };

            replyEmotion();

            // 对评论的回复(动画)
	        $('.open-cc').click(function(){
	            $(this).closest('.comment-function').find('.comment-comment').toggle();
	            var replyTarget = $(this).closest('.comment-function').find('.comment-comment textarea');
	            replyTarget.focus();

	          //  console.log(replyTarget);

	            var thisname = $(this).closest('.comment-content').find('.commenter-name .name').text();
	            if (!$(this).closest('.comment-function').find('.comment-comment textarea').val() ) {
	                $(this).closest('.comment-function').find('.comment-comment textarea').val("回复@"+thisname+":");
	            };

	            // replyEmotion();
	            
	            
	        });
	        // 回复
	        $('.btn-cc-submit').click(function() {
	        	var thisobject = $(this);
	        	var fid = $(this).closest('.xxs-item').attr('data-xxsid');
	            var rfcuid = $(this).closest('.comment-item').attr('data-xxfcuid');
	            var content = $(this).closest('.comment-function').find('.comment-comment textarea').val();
	            var rcontent = $(this).closest('.comment-item').find('.comment-text').html();
	             
	             if (content.substring(content.indexOf(":")+1).length == 0) {
	                 $().message("回复内容不能为空！");
                     return;
	             }
	             if (content.length > 200) {
	                $().message("回复内容太长！");
	                return;
	             }
	             
	             var input = $(this).closest('.comment-comment').find('input');
	             var tflag = 0;
                 if (input.attr("checked") == "checked") {
                    tflag = 1;
                 }
                 
	             var fun=function(data){
	            	 //console.log(thisobject);
	            	 if(data.s==1){
                       thisobject.closest('.comment-function').find('.comment-comment textarea').val("");
                       input.attr("checked",false);
                       // 修改评论的次数
                       thisobject.closest('.xxs-item').find('.btn-xxs-comment ').html("评论("+data.ccount+")");
                       // 刷新评论列表
                       
                       searchComment(fid,thisobject);
               
                       } 
                   };
                   exeAjax(
                        ajaxUrl("${aier_url}${aier_urijs}userhomeforums_commentFresh${aier_suffix}"),
                        fun,{
                            "fid":fid,
                            "rfcuid":rfcuid,
                            "content":content,
                            "rcontent":rcontent,
                            "ctype":2,
                            "flag":tflag
                            
               		});
		        });// click end
       } 
   };
   exeAjax(
        ajaxUrl("${aier_url}${aier_urijs}userhomeforums_searchCommentByFid${aier_suffix}"),
        fun,{
            "fid":fid
   });
}
    
// 删除新鲜事
function deleteFresh(fid) {
    $(function() {
        $("#deleteConfirm").dialog(
            {
                //背景变暗
                modal : true,
                autoOpen : false,
                show : "fade",
                hide : "fade",
                width : "340",
                height : "220",
                buttons : {
                    "确定" : function() {
                        // 获取新鲜事列表
                        var fun=function(data){
                            if(data.s==1){
                                $("#deleteConfirm").dialog("close");
                                searchAllFresh(page);
                            } else {
                                $("#deleteConfirm").dialog("close");
                                $().message("删除失败，请稍后再试！");
                            }
                            
                        };
                        exeAjax(
                             ajaxUrl("${aier_url}${aier_urijs}userhomeforums_deleteFresh${aier_suffix}"),
                             fun,{
                                "fid":fid
                        });
                    },
                    "取消" : function() {
                        $(this).dialog("close");
                    }
            }
        });
        $("#deleteConfirm").dialog("open");
    });
    
}
    
    
// #10
// 插入@插入@插入@插入@插入@插入@插入@插入@插入@插入@插入@插入@

$('#xxsTextarea').bind('click keyup',function() {

	 // 正则
	var brRegExp    = /\r\n|\n/g; //换行
	var spaceRegExp = /\s/g; //空格
	var atRegExp    = /\@/g; //@符
	var at          = /^@{1}[\u4e00-\u9fa5_-a-zA-Z0-9]{0,24}$/g;     //匹配@和昵称
	var bianjie     = /\B@{1}[\u4e00-\u9fa5\_\-a-zA-Z0-9]{2,24}/g; //匹配@和昵称的边界

	// 声明jquery对象
	var $textareaObj = $(this);
	var $list = $('#list');
	var $hidden = $('#hidden');

	// 声明琐碎内容
	var content = $textareaObj.val();
	var caret = $textareaObj.caretPosition();

	// 生成隐藏textarea
	var toX = $textareaObj.offset().left,
		toY = $textareaObj.offset().top;

	createHidden(toX,toY);


	// console.log('___插入位置__'+caret);

	var before = content.substring(0,caret);
	var beforeCaret = content.substring(caret-1,caret);

	// console.log(caret,beforeCaret,spaceRegExp.test(beforeCaret));

	// 空格作为断字标记
	if ( spaceRegExp.test(beforeCaret) == false ) {

		// console.log(before);

		var a = before.lastIndexOf('@'); //存在问题
		// console.log(a);

		if ( a > -1) {

			var beforeAt = content.substring(0,a);
			var afterAt  = content.substring(a+1);

			var spaceTpl = '<span style="white-space:pre-wrap;"> </span>';
			var brTpl = '<br>';
			beforeAt = beforeAt.replace(brRegExp,brTpl);
			beforeAt = beforeAt.replace(spaceRegExp,spaceTpl);
			

			$('#hidden>.before').html(beforeAt);
			$('#hidden>.at').html('@');
			$('#hidden>.after').html(afterAt);

			var hlX = $('#hidden>.at').offset().left + 4,
				hlY = $('#hidden>.at').offset().top + 20 - $textareaObj.scrollTop();

			showList(hlX,hlY);

			var keyword = content.substring(a+1,caret);
			// console.log( a+1,caret);
			var list = $('#list');


			findFriend(keyword,list,followList);

			// 插入昵称

			$('#list a').click(function(){

				var text = $(this).attr('data-nickname');
				var start = a+1;
				var end = caret;

				insertText(text,start,end);

			});




		} else {
			hideList();
		}

	} else {
		hideList();
	}

	function showList(x,y) {
		$('#list').css({
			display	 : 'block',
			left: x,
			top: y
		});

	};

	function hideList() {
		$('#list').hide();
	};

	function createHidden(x,y) {
		var hiddenTpl = '<span class="before"></span><span class="at"></span><span class="after"></span>';
		$('#hidden').html(hiddenTpl);
		$('#hidden').css({
			display  : 'block',
			left: x,
			top: y
		});
	};

	function removeHidden() {
		$('#hidden').remove();
	};

	function findFriend( keyword,list,followList ) {
		var nPos;
		var vResult = [];

		if (!isnull(followList)) {
		   for(var i in followList) {
		        var sTxt = '';
		        if (!isnull(followList[i].nickname)) {
		           sTxt = followList[i].nickname;
		        }
		        if (!isnull(followList[i].remark)) {
		           sTxt += '(' + followList[i].remark + ')';
		        }
		        //var sTxt=followList[i].nickname||'';
		        nPos=sTxt.indexOf(keyword);
		        if(nPos>=0) {
		            vResult[vResult.length] = followList[i];
		        }
		    }
		}
		
		if (vResult.length == 0) {
			list.html('<div class="title" style="width: auto;">轻敲空格完成输入</div>');
		} else {
			sCallback(vResult);
		}
			
		function sCallback(vResult) {
			list.html('<div class="title">选择你想@的人或直接输入</div><ul></ul>');
			var htmlTpl='<li><a href="javascript:void(0);" data-nickname=""></a></li>'; // 这是一个模版
			for (var i = 0; i < vResult.length && i < 10; i++) {
				list.find('ul').append(htmlTpl);
				var target = list.find('li').last().children('a');
				// 从这里开始填内容（拼html）
				if (!isnull(vResult[i].remark)) {
					target.attr('data-nickname',vResult[i].nickname);
				    target.html(vResult[i].nickname + '('+ vResult[i].remark +')');
				} else {
					target.attr('data-nickname',vResult[i].nickname);
				    target.html(vResult[i].nickname);
				}
				 
			};

		}
	 
	} //  生成好友列表结束

	function insertText(text,start,end) {
		// console.log(text.length,content);

		$textareaObj.val( $textareaObj.val().substring(0, start) + text + $textareaObj.val().substring(end, $textareaObj.val().length) + " " );
	  //   this.selectionStart = this.selectionEnd = start + text.length;

	  	$textareaObj.caretPosition(end+text.length+1);
	  	$('#list').hide();
	} // insertText 结束

}); // 插入@结束

    
</script>
</body>
</html>